<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ChannelManagerDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateChannelManagerRequest;
use App\Http\Requests\UpdateChannelManagerRequest;
use App\Repositories\ChannelManagerRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ChannelManagerController extends AppBaseController
{
    /** @var  ChannelManagerRepository */
    private $channelManagerRepository;

    public function __construct(ChannelManagerRepository $channelManagerRepo)
    {
        $this->channelManagerRepository = $channelManagerRepo;
    }

    /**
     * Display a listing of the ChannelManager.
     *
     * @param ChannelManagerDataTable $channelManagerDataTable
     * @return Response
     */
    public function index(ChannelManagerDataTable $channelManagerDataTable)
    {
        return $channelManagerDataTable->render('backend.channel_managers.index');
    }

    /**
     * Show the form for creating a new ChannelManager.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.channel_managers.create');
    }

    /**
     * Store a newly created ChannelManager in storage.
     *
     * @param CreateChannelManagerRequest $request
     *
     * @return Response
     */
    public function store(CreateChannelManagerRequest $request)
    {
        $input = $request->all();

        $channelManager = $this->channelManagerRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Channel Manager']));

        return redirect(route('channelManagers.index'));
    }

    /**
     * Display the specified ChannelManager.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $channelManager = $this->channelManagerRepository->findWithoutFail($id);

        if (empty($channelManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Manager']));

            return redirect(route('channelManagers.index'));
        }

        return view('backend.channel_managers.show')->with('channelManager', $channelManager);
    }

    /**
     * Show the form for editing the specified ChannelManager.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $channelManager = $this->channelManagerRepository->findWithoutFail($id);

        if (empty($channelManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Manager']));

            return redirect(route('channelManagers.index'));
        }

        return view('backend.channel_managers.edit')->with('channelManager', $channelManager);
    }

    /**
     * Update the specified ChannelManager in storage.
     *
     * @param  int              $id
     * @param UpdateChannelManagerRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateChannelManagerRequest $request)
    {
        $channelManager = $this->channelManagerRepository->findWithoutFail($id);

        if (empty($channelManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Manager']));

            return redirect(route('channelManagers.index'));
        }

        $channelManager = $this->channelManagerRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Channel Manager']));

        return redirect(route('channelManagers.index'));
    }

    /**
     * Remove the specified ChannelManager from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $channelManager = $this->channelManagerRepository->findWithoutFail($id);

        if (empty($channelManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Manager']));

            return redirect(route('channelManagers.index'));
        }

        $this->channelManagerRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Channel Manager']));

        return redirect(route('channelManagers.index'));
    }
}
